<template>
  <div>
    <div>
      <span>SMCR</span>
      <el-input v-model="inputVal" size="mini" class="input" placeholder="请输入内容" @dblclick.native="smcrDbClick" @blur="updateFooterEvent"/>
      <el-button v-if="limits.length >= 1 && limits.filter(it => it.FName === '新增').length" size="mini" type="primary" @click="saveRanyou">保存</el-button>
      <el-button v-if="limits.length >= 1 && limits.filter(it => it.FName === '基础设置查看').length" size="mini" type="primary" @click="settingRy">基础设置查看</el-button>

      <el-dialog v-el-drag-dialog :visible.sync="setModal" :close-on-click-modal="false" :show-close="true" class="drag-set-modal" width="90%">
        <el-row>
          <el-input v-model="keyword" size="small" clearable class="input drag-input" placeholder="请输入内容" @blur="searchSet"/>
          <el-select v-model="fobjectname" allow-create filterable size="small" class="input drag-select" clearable placeholder="请选择" @change="searchSet">
            <el-option
              v-for="item in fobjectnameList"
              :key="item.fobject"
              :label="item.fobjectname"
              :value="item.fobjectname"/>
          </el-select>
        </el-row>
        <vxe-grid
          id="toolbar_demo_1"
          ref="setTable"
          :print-config="{}"
          :import-config="{}"
          :export-config="{}"
          :form-config="formConfig"
          :columns="tableColumn"
          :toolbar-config="tableToolbar"
          :data="tableData"
          :custom-config="{storage: true}"
          :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
          align="center"
          height="650"
          border
          resizable
          keep-source
          @toolbar-button-click="toolbarButtonClickEvent"
          @toolbar-tool-click="toolbarToolClickEvent">

          <template #keyword_item="{ data }">
            <vxe-input v-model="data.keyword" type="text" placeholder="请输入名称"/>
          </template>
          <template #fobjectid_edit="{ row }">
            <vxe-input v-model="row.fobjectid"/>
          </template>
          <template #fobjectname_edit="{ row }">
            <vxe-input v-model="row.fobjectname"/>
          </template>
          <template #ffuhe_edit="{ row }">
            <vxe-input v-model="row.ffuhe"/>
          </template>
          <template #ffuheval_edit="{ row }">
            <vxe-input v-model="row.ffuheval"/>
          </template>
          <template #fsjtime_edit="{ row }">
            <vxe-input v-model="row.fsjtime"/>
          </template>
          <template #fyxtime_edit="{ row }">
            <vxe-input v-model="row.fyxtime"/>
          </template>
          <template #fyh_edit="{ row }">
            <vxe-input v-model="row.fyh"/>
          </template>
          <template #fmaxyhval_edit="{ row }">
            <vxe-input v-model="row.fmaxyhval"/>
          </template>
          <template #fsetkey_edit="{ row }">
            <vxe-input v-model="row.fsetkey"/>
          </template>
          <template #fsort_edit="{ row }">
            <vxe-input v-model="row.fsort"/>
          </template>

          <template #fsjtime1_edit="{ row }">
            <vxe-input v-model="row.fsjtime1"/>
          </template>
          <template #fmaxyh_edit="{ row }">
            <vxe-input v-model="row.fmaxyh"/>
          </template>
          <template #fryxhl_edit="{ row }">
            <vxe-input v-model="row.fryxhl"/>
          </template>
          <template #fqigangyh_edit="{ row }">
            <vxe-input v-model="row.fqigangyh"/>
          </template>
          <template #fnaoh_edit="{ row }">
            <vxe-input v-model="row.fnaoh"/>
          </template>
          <template #fnsxh_edit="{ row }">
            <vxe-input v-model="row.fnsxh"/>
          </template>
          <template #fyryxh_edit="{ row }">
            <vxe-input v-model="row.fyryxh"/>
          </template>
          <!--
"fid":1,
"fpower":0,
"fcreatetime":"2022-12-29 15:35:08",
"fmaxyh":0, // 最大油耗率(g/KWh)
"fryxhl":0, // 燃油消耗量(kg)
"ftype":0,
"fremark":"",
"fqigangyh":"1.60", // 气缸油耗率（g/kWh）
"fsjtime1":"0", //11
"fnaoh":0, // NaOH消耗率（l/h）
"fnsxh":0, // NaOH消耗量(l)
"fyryxh":0, // // 引燃油耗率（g/kWh）
"fsetkeyname":""
 -->

        </vxe-grid>
      </el-dialog>

      <el-dialog
        v-el-drag-dialog
        :visible.sync="cbModal"
        :close-on-click-modal="false"
        :show-close="true"
        class="cb-set-modal"
        width="70%">
        <div >
          <div v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length" style="height:50px;">
            <el-input v-model="cbKeyword" clearable style="width: 160px;" placeholder="请输入关键字" @keyup.native.enter="cbSearch" @change="cbSearch"/>
            <el-button type="primary" icon="el-icon-search" @click="cbSearch">搜索</el-button>
            <el-button type="primary" @click="cbConfirm">确认</el-button>
          </div>
          <el-table
            v-loading="cbLoading"
            v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
            ref="cbTable"
            :data="cbTableData"
            :summary-method="cbGetSummaries"
            :header-cell-style="tableHeaderStyle"
            max-height="600"
            class="tableCss single-select-table"
            element-loading-text="正在加载"
            border
            highlight-current-row
            @selection-change="cbHandleSelectionChange"
            @current-change="cbSalaryCurrentChange">
            <el-table-column
              type="selection"
              width="55"/>
            <template v-for="item in cbFormThead">
              <el-table-column v-if="item.frpttypeflag ==0" :key="item.fid" :label="item.frepcap" :prop="item.frepfld" :width="item.frepwid" align="center" show-overflow-tooltip>

                <template slot-scope="scope">
                  <template v-if="item.frephide<=0">
                    <template v-if="item.frepfld === 'fstatus'">
                      <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                      <el-tag v-else size="mini" type="danger">未审</el-tag>
                    </template>
                    <template v-else size="mini">
                      {{ scope.row[item.frepfld] }}
                    </template>
                  </template>
                </template>

              </el-table-column>
            </template>
          </el-table>

          <el-pagination
            v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
            :total="cbTotal"
            :page-sizes="cbPagesizes"
            :page-size="cbPagesize"
            :current-page.sync="cbCurrentPage"
            class="jy-pagination"
            style="text-align: center; margin-top: 20px;"
            background
            layout="sizes, prev, pager, next, total"
            @size-change="cbHandleSizeChange"
            @current-change="cbHandleCurrentChange"/>
        </div>
      </el-dialog>
    </div>
    <div class="top">
      <!-- <div class="xTable"> -->
      <vxe-table
        ref="xTable"
        :data="mhtzTableData"
        :footer-method="footerMethod1"
        :merge-footer-items="mergeFooterItems"
        :footer-cell-class-name="mhtzFooterCellClassName"
        class="xTable"
        stripe
        border
        align="center"
        show-footer>
        <vxe-column type="seq" width="100"/>
        <vxe-colgroup title="磨合过程">
          <vxe-colgroup title="负荷运行过程">
            <vxe-column field="ffuhe" width="160" title="负荷"/>
            <vxe-column field="fpower" title="功率(KW)">
              <template #default="{ row }">
                <span>{{ Math.ceil(countFpower(row)) }} </span>
              </template>
            </vxe-column>
            <vxe-colgroup title="升降时间(分钟)">
              <vxe-column field="fsjtime" width="60" />
              <vxe-column field="fsjtime1" width="60" />
            </vxe-colgroup>
            <vxe-column field="fyxtime" title="运行时间(分钟)" width="60">
              <template #default="{ row }">
                <span>{{ Math.ceil(row.fyxtime) }} </span>
              </template>
            </vxe-column>
            <vxe-column field="fyh" title="对应油耗率(g/KWh)"/>
            <vxe-column field="fmaxyh" title="最大油耗(g/KWh)"/>
            <vxe-column field="fqigangyh" title="气缸油耗率(g/kWh)"/>
            <vxe-column :edit-render="{}" field="fryxhl" title="燃油消耗量(kg)"/>
            <vxe-column :edit-render="{}" field="fqgyxhl" title="气缸油消耗量(kg)"/>
          </vxe-colgroup>
        </vxe-colgroup>
      </vxe-table>
      <!-- </div> -->

      <!-- <div class="fhsjTable"> -->
      <vxe-table
        ref="fhsjTable"
        :data="fhsjTableData"
        :footer-method="fhsjMethod"
        :merge-footer-items="fhsjMergeFooterItems"
        :footer-cell-class-name="footerCellClassName"
        class="fhsjTable"
        stripe
        border
        align="center"
        show-footer>
        <vxe-column type="seq" width="100"/>
        <vxe-colgroup title="负荷升降过程估算">
          <vxe-column field="ffuhe" width="160" title="负荷"/>
          <vxe-column field="fpower" title="功率(KW)">
            <template #default="{ row }">
              <span>{{ Math.ceil(fhsjCountFpower(row)) }} </span>
            </template>
          </vxe-column>
          <vxe-colgroup title="升降时间(分钟)">
            <vxe-column field="fsjtime" width="60" />
            <vxe-column field="fsjtime1" width="60" />
          </vxe-colgroup>
          <vxe-column field="fyxtime" title="运行时间(分钟)" width="60" />
          <vxe-column field="fyh" title="对应油耗率(g/KWh)"/>
          <vxe-column field="fmaxyh" title="最大油耗(g/KWh)"/>
          <vxe-column field="fqigangyh" title="气缸油耗率(g/kWh)"/>
          <vxe-column :edit-render="{}" field="fryxhl" title="燃油消耗量(kg)"/>
          <vxe-column :edit-render="{}" field="fqgyxhl" title="气缸油消耗量(kg)"/>
        </vxe-colgroup>
      </vxe-table>
    </div>

  </div>
</template>
<script>
const FRepKey = 29002
let opername = ''
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import { common } from '../../mixins/common'
import { cgMainranyouSave, cgMainranyou, ranyouList, ranyouSave, getRanYouSet, ranYouSetAdd } from '../../api/rygl'
import { configColumn } from '../../api/salary'
import { genList } from '../../api/gen'
import '../../styles/vxetable.scss'
import HeadTable from '../salary/headTable/Billindex.vue'

import VXETablePluginShortcutKey from 'vxe-table-plugin-shortcut-key'
VXETable.use(VXETablePluginShortcutKey, {
  // 功能键设置
  setting: {
    'table.edit.tab.rightMove': 'Enter',
    'table.edit.tab.leftMove': 'shift + Tab'
  }
})

export default {
  components: {
    HeadTable
  },
  mixins: [common],
  data() {
    return {
      fbillno: '',
      fmodel: '',
      rows: [],

      cbKeyword: '',
      cbFstatus: '',
      cbFbrand: '',

      cbFormThead: [],
      cbModal: false,
      cbLoading: false,
      cbTableData: [],
      cbTableList: [],
      cbTotal: 0,
      cbCurrentPage: 1,
      cbPagesize: 20,
      cbPagesizes: [20, 50, 100, 300, 500, 1000, 2000, 3000, 5000, 10000],

      opername: '',
      fobjectname: '',
      fobjectnameList: [
        {
          fobject: 29002,
          fobjectname: '磨合调整'
        },
        {
          fobject: 29003,
          fobjectname: '燃油模式'
        },
        {
          fobject: 29004,
          fobjectname: '燃油+SCR/EGR模式'
        },
        {
          fobject: 29005,
          fobjectname: '燃油模式(iCER)'
        },
        {
          fobject: 29006,
          fobjectname: '燃气模式'
        },
        {
          fobject: 29007,
          fobjectname: '燃气模式(iCER)'
        }
      ],
      tableData: [],
      tableToolbar: {
        size: 'small',
        buttons: [
          { code: 'search', status: 'primary', name: '搜索' },
          { code: 'myInsert', visible: true, name: '新增' },
          { code: 'mySave', visible: true, name: '保存', status: 'success' },
          { code: 'myDelete', visible: true, name: '删除', status: 'primary' },
          { code: 'myFresh', name: '刷新', status: 'primary' }
        ]
        // refresh: true
        // import: true,
        // export: true,
        // print: true,
        // zoom: true,
        // custom: true
      },
      formConfig: {
        data: {
          keyword: ''
        }
      },
      data: [],
      tableColumn: [
        { type: 'checkbox', width: 50 },
        { type: 'seq', width: 60 },
        { field: 'fobjectid', title: '对象号', editRender: {}, slots: { edit: 'fobjectid_edit' }},
        { field: 'fobjectname', title: '对象名称', editRender: {}, slots: { edit: 'fobjectname_edit' }},
        { field: 'ffuhe', title: '负荷', editRender: {}, slots: { edit: 'ffuhe_edit' }},
        { field: 'ffuheval', title: '负荷值', editRender: {}, slots: { edit: 'ffuheval_edit' }},

        { title: '升降时间(分钟)',
          children: [
            { field: 'fsjtime' },
            { field: 'fsjtime1' }
          ]

        },
        // { field: 'fsjtime1', title: '升降时间(分钟)', editRender: {}, slots: { edit: 'fsjtime1_edit' }},

        { field: 'fyxtime', title: '运行时间(分钟)', editRender: {}, slots: { edit: 'fyxtime_edit' }},
        { field: 'fyh', title: '对应油耗(g/KWh)', editRender: {}, slots: { edit: 'fyh_edit' }},
        { field: 'fmaxyhval', title: '最大油耗比例', showOverflow: true, editRender: {}, slots: { edit: 'fmaxyhval_edit' }},
        // { field: 'fmaxyh', title: '最大油耗率(g/KWh)', showOverflow: true, editRender: {}, slots: { edit: 'fmaxyh_edit' }},
        // { field: 'fryxhl', title: '燃油消耗量(kg)', showOverflow: true, editRender: {}, slots: { edit: 'fryxhl_edit' }},
        { field: 'fqigangyh', title: '气缸油耗率（g/kWh）', showOverflow: true, editRender: {}, slots: { edit: 'fqigangyh_edit' }},

        { field: 'fnaoh', title: 'NaOH消耗率（l/h）', showOverflow: true, editRender: {}, slots: { edit: 'fnaoh_edit' }},
        { field: 'fyryxh', title: '引燃油耗率（g/kWh）', showOverflow: true, editRender: {}, slots: { edit: 'fyryxh_edit' }},
        { field: 'fnsxh', title: '尿素消耗率（l/h）', showOverflow: true, editRender: {}, slots: { edit: 'fnsxh_edit' }},

        // { field: 'fsetkeyname', title: '燃油表头', showOverflow: true, editRender: {}, slots: { edit: 'fsetkeyname_edit' }},
        { field: 'fsetkey', title: '设置key', showOverflow: true, editRender: {}, slots: { edit: 'fsetkey_edit' }},
        { field: 'fsort', title: '排序', showOverflow: true, editRender: {}, slots: { edit: 'fsort_edit' }}
      ],

      setModal: false,
      options: [],
      setTableData: [],
      keyword: '',
      // 用户菜单
      menusList: [],
      limits: [],
      inputVal: 0,
      mergeFooterItems: [{ row: 0, col: 1, rowspan: 1, colspan: 6 }],
      mhtzTableData: [],
      fhsjMergeFooterItems: [
        { row: 0, col: 1, rowspan: 1, colspan: 6 },
        { row: 1, col: 1, rowspan: 1, colspan: 6 }
      ],
      fhsjTableData: [],

      nbtjMergeFooterItems: [{ row: 0, col: 1, rowspan: 1, colspan: 6 }],
      nbtjTableData: [],

      fhsj2MergeFooterItems: [
        { row: 0, col: 1, rowspan: 1, colspan: 6 },
        { row: 1, col: 1, rowspan: 1, colspan: 6 }
      ],
      fhsj2TableData: [],

      zyqMergeFooterItems: [{ row: 0, col: 1, rowspan: 1, colspan: 6 }],
      zyqTableData: [],

      qtMergeFooterItems: [
        { row: 0, col: 1, rowspan: 1, colspan: 6 },
        { row: 1, col: 1, rowspan: 1, colspan: 6 },
        { row: 2, col: 1, rowspan: 1, colspan: 6 }
      ],
      qtTableData: []
    }
  },
  async created() {
    this.opername = decodeURIComponent(this.globalDb.fname)
    opername = decodeURIComponent(this.globalDb.fname)

    await this.getRanyouList()
    await this.getCgMainranyou()
    // 弹窗数据
    await this.getCbBodyData()
    await this.getCbHeadData()

    // 菜单列表（权限）
    const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
    this.menusList = menuRes
    if (menuRes.length >= 1) {
      menuRes.map(it => {
        it.children.map(item => {
          if (item.fobjectid === FRepKey) {
            this.$set(this, 'limits', item.child)
          }
        })
      })
    }

    const buttons = this.tableToolbar.buttons
    this.$set(buttons[1], 'visible', !!(this.limits.length >= 1 && this.limits.filter(it => it.FName === '基础设置新增').length))
    this.$set(buttons[2], 'visible', !!(this.limits.length >= 1 && this.limits.filter(it => it.FName === '基础设置保存').length))
    this.$set(buttons[3], 'visible', !!(this.limits.length >= 1 && this.limits.filter(it => it.FName === '基础设置删除').length))
    this.$set(this.tableToolbar, 'buttons', buttons)
  },
  methods: {
    async smcrDbClick() {
      this.cbModal = true
    },
    async cbSearch() {
      await this.getCbBodyData()
      await this.getCbHeadData()
    },
    cbConfirm() {
      if (this.rows && this.rows.length) {
        // console.log(this.rows, ' this.rows')
        this.fbillno = this.rows[0].fbillno
        this.fmodel = this.rows[0].fmodel
        this.inputVal = this.rows[0].fhtpower
        this.cbModal = false
      } else {
        this.$message({
          type: 'error',
          message: '请选中一行数据'
        })
      }
    },
    cbGetSummaries() {
      return []
    },
    cbHandleSelectionChange(rows) {
      if (rows.length) {
        this.rows = rows
      }
      if (rows.length > 1) {
        this.$refs.cbTable.clearSelection()
        this.$refs.cbTable.toggleRowSelection(rows.pop())
      }
    },
    cbSalaryCurrentChange() {

    },
    async cbHandleSizeChange(val) {
      this.cbCurrentPage = 1
      this.cbPagesize = val
      await this.getCbBodyData()
      await this.getCbHeadData()
    },
    async cbHandleCurrentChange(val) {
      this.cbCurrentPage = val
      await this.getCbBodyData()
      await this.getCbHeadData()
    },

    // 表头数据
    async getCbHeadData() {
      try {
        this.cbLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          // FRepKey: 14009
          FRepKey: 1400902
        })
        this.cbLoading = false
        this.cbFormThead = res.Data
        // this.cbFormThead.length = 8
        // if (res.Error === 0) {
        //   if (res.Data.length) {
        //     res.Data.map(item => {
        //       if (item.frepfld === 'fmodel') {
        //         this.cbFormThead[0] = item
        //       } else if (item.frepfld === 'fsjpower') {
        //         this.cbFormThead[1] = item
        //       } else if (item.frepfld === 'fhtpower') {
        //         this.cbFormThead[2] = item
        //       } else if (item.frepfld === 'fsxtaishu') {
        //         this.cbFormThead[3] = item
        //       } else if (item.frepfld === 'fbillno') {
        //         this.cbFormThead[4] = item
        //       } else if (item.frepfld === 'fcustomer') {
        //         this.cbFormThead[5] = item
        //       } else if (item.frepfld === 'fcustomername') {
        //         this.cbFormThead[6] = item
        //       } else if (item.frepfld === 'fmodelno') {
        //         this.cbFormThead[7] = item
        //       }
        //       return this.cbFormThead
        //     })
        //   } else {
        //     return []
        //   }
        // }

        // console.log(this.cbFormThead, ' this.cbFormThead')
        // 机型  功率 生效台数 流水号

        // this.oriColumnData = res.Data

        this.cbFormThead.map(item => {
          this.cbTableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.cbTableData = this.cbTableList.slice()

        // 获取显示表头键值对
        this.cbFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.cbTableList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })
        // fmodel 机型
        // fsxtaishu 生效台数
        // fsjpower 设计功率
        // fhtpower 合同功率
        // fcustomer 项目客户
        // fcustomername 船东
        // fmodelno 船型和船号

        // console.log(this.cbFormThead, ' this.cbFormThead')

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.cbLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getCbBodyData() {
      try {
        this.cbLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.cbKeyword,

          fstatus: this.cbFstatus,
          limit: this.cbPagesize,
          page: this.cbCurrentPage,
          tkkey: 29002,
          FRepKey: 14009
        })
        this.cbLoading = false

        this.cbTableList = res.Data
        this.cbTotal = res.total
      } catch (error) {
        this.cbLoading = false
      }
    },
    async toolbarButtonClickEvent({ code }) {
      const $grid = this.$refs.setTable
      const { insertRecords, removeRecords, updateRecords } = $grid.getRecordset()
      const { tableData } = $grid.getTableData()
      switch (code) {
        case 'search':
          this.getRanYouSetList()
          break
        case 'myInsert':
          $grid.insertAt(-1, -1)
          break
        case 'mySave':

          if (insertRecords.length === 0 && updateRecords.length === 0 && removeRecords.length === 0) {
            VXETable.modal.message({ content: `新增 ${insertRecords.length} 条，更新 ${updateRecords.length} 条`, status: 'warning', zIndex: 99999 })
            return
          }

          try {
            const res = await ranYouSetAdd({
              FRepKey,
              opername: this.opername,
              insertRecords,
              updateRecords,
              removeRecords,
              tableData
              // formdata: this.formData
            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }

          break
        case 'myDelete':
          if ($grid.getCheckboxRecords().length === 0) {
            VXETable.modal.message({ content: `请选中一行`, status: 'warning' })
            return
          }
          setTimeout(async() => {
            const { removeRecords } = $grid.getRecordset()
            $grid.removeCheckboxRow()
            try {
              const res = await ranYouSetAdd({
                FRepKey,
                opername: this.opername,
                insertRecords,
                updateRecords,
                removeRecords,
                tableData
              // formdata: this.formData
              })
              if (res.Error === 0) {
                this.$message({
                  message: res.Message,
                  type: 'success'
                })
              }
            } catch (error) {
              console.log(error)
            }
          })
          break
        case 'myFresh':
          this.getRanYouSetList()
          break
      }
    },
    toolbarToolClickEvent({ code }) {
      const $grid = this.$refs.xGrid
      switch (code) {
        case 'myPrint':
          $grid.print()
          break
      }
    },
    async saveRanyou() {
      try {
        const res = await ranyouSave({
          opername: decodeURIComponent(this.globalDb.fname),
          fobjectid: FRepKey,
          cmcr: this.inputVal,
          fbillno: this.fbillno,
          fmodel: this.fmodel
        })
        console.log(res.Data, ' res saveRanyou')
        if (res.Error === 0) {
          this.$message({
            message: '数据保存成功',
            type: 'success'
          })
          await this.getRanyouList()
          await this.getCgMainranyou()
          this.mergeFooterItems = [{ row: 0, col: 1, rowspan: 1, colspan: 6 }]
          this.fhsjMergeFooterItems = [
            { row: 0, col: 1, rowspan: 1, colspan: 6 },
            { row: 1, col: 1, rowspan: 1, colspan: 6 }
          ]
          this.nbtjMergeFooterItems = [{ row: 0, col: 1, rowspan: 1, colspan: 6 }]
          this.fhsj2MergeFooterItems = [
            { row: 0, col: 1, rowspan: 1, colspan: 6 },
            { row: 1, col: 1, rowspan: 1, colspan: 6 }
          ]
          this.zyqMergeFooterItems = [{ row: 0, col: 1, rowspan: 1, colspan: 6 }]
          this.qtMergeFooterItems = [
            { row: 0, col: 1, rowspan: 1, colspan: 6 },
            { row: 1, col: 1, rowspan: 1, colspan: 6 },
            { row: 2, col: 1, rowspan: 1, colspan: 6 }
          ]
        } else {
          this.$message({
            message: res.Message || '数据保存失败',
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    async settingRy() {
      this.setModal = true
      await this.getRanYouSetList()
    },
    refresh() {
      this.getRanYouSetList()
    },
    vxeAdd(row) {
      const $grid = this.$refs.setTable
      // $grid.insertAt(row, -1)
      $grid.insert({
        fobjectid: ''
      })
    },
    vxeDel() {
      const $grid = this.$refs.setTable
      $grid.remove($grid.getCurrentRecord())
    },
    vxeU8() {

    },
    goBack() {

    },
    vxeSendSms() {

    },
    selectSettings() {

    },
    searchSet() {
      this.getRanYouSetList()
    },
    async getRanYouSetList() {
      try {
        const res = await getRanYouSet({
          opername: decodeURIComponent(this.globalDb.fname),
          fobjectname: this.fobjectname,
          keyword: this.keyword
        })
        // console.log(res.Data, ' res getRanYouSet')
        if (res.Error === 0) {
          // const setTableData = res.Data.filter(it => it.fsetkey === 'fmhfhsj')
          // console.log(setTableData, ' setTableData')
          // this.setTableData = setTableData
          this.tableData = res.Data
        }
      } catch (error) {
        console.log(error)
      }
    },
    async getRanyouList() {
      try {
        const res = await ranyouList({
          opername: decodeURIComponent(this.globalDb.fname),
          fobjectid: FRepKey
        })
        // 29002  常规主燃油
        // 磨合调整过程  -- 负荷运行  fmhfhyx
        // 负荷升降估算  fmhfhsj

        // 内部提交和FAT过程  fnbfhyx
        // 负荷升降估算  fnbfhsj

        // 增压器匹配和性能调整  fzyqxn
        // 其他运行（含故障/功能性试验/安保试验等）  fqtyx
        // console.log(res.Data, ' res getRanyouList')
        if (res.Error === 0) {
          this.mhtzTableData = res.Data.ffuheyx
          this.fhsjTableData = res.Data.ffuhesj
        }
      } catch (error) {
        console.log(error)
      }
    },
    async getCgMainranyou() {
      try {
        const res = await cgMainranyou({
          opername: decodeURIComponent(this.globalDb.fname),
          fobjectid: FRepKey
        })
        if (res.Error === 0) {
          this.inputVal = res.Data[0].fvalue
        }
      } catch (error) {
        console.log(error)
      }
    },
    async save() {
      try {
        const res = await cgMainranyouSave({
          opername: decodeURIComponent(this.globalDb.fname),
          fobjectid: FRepKey,
          cmcr: this.inputVal
        })
        console.log(res, ' res')
      } catch (error) {
        console.log(error)
      }
    },
    countFpower(row) {
      return Number(row.fpower)
    },
    updateFooterEvent() {
      const $table = this.$refs.xTable
      if ($table) {
        $table.updateFooter()
      }
      const $fhsjTable = this.$refs.fhsjTable
      if ($fhsjTable) {
        $fhsjTable.updateFooter()
      }
    },
    xhlCal(row, field, time = 'fyxtime') {
      // 燃气消耗量（kg）    = 最大气号率 * 功率(kW) * ( 运行时间 / 60) * 0.001
      // 气缸油消耗量        = 气缸油耗率 * 功率(kW) * ( 运行时间 / 60) * 0.001
      // 引燃油消耗量        = 引燃油耗率 * 功率(kW) * ( 运行时间 / 60) * 0.001
      if (time === 'fsjtime') {
        console.log(field, ' field', row)
      }
      return (Number(row[field]) * Number(row.fpower) * (Number(row[time]) / 60) * 0.001)
    },
    naoXhlCal(row, field, time = 'fyxtime') {
      // NaOH消耗量         = ( 运行时间 / 60) * NaOH消耗率
      return (Number(row[time]) / 60) * Number(row[field])
    },
    // 燃油消耗量(kg)
    fryxhlCal(row) {
      return Number(row.fryxhl)
    },
    // 气缸油消耗量(kg)
    fqgyxhlCal(row) {
      return Number(row.fqgyxhl)
    },
    xhlCalAll: function() {
      let count1 = 0
      let count2 = 0
      this.mhtzTableData.forEach(row => {
        count1 += parseFloat(this.fryxhlCal(row))
        count2 += parseFloat(this.fqgyxhlCal(row))
      })

      let count3 = 0
      let count4 = 0
      this.fhsjTableData.forEach(row => {
        count3 += parseFloat(this.fryxhlCal(row))
        count4 += parseFloat(this.fqgyxhlCal(row))
      })

      return {
        count1: Number(count1), count2: Number(count2),
        count3: Number(count3), count4: Number(count4)
      }
    },

    mhtzFooterCellClassName({ $rowIndex, columnIndex }) {
      if (columnIndex === 7 || columnIndex === 8) {
        if ($rowIndex === 0) {
          return 'col-blue'
        }
      }
    },
    // 表尾数据
    footerMethod1({ columns, data }) {
      setTimeout(() => {
        const $xTable = this.$refs.xTable
        if ($xTable) {
          $xTable.updateFooter()
        }
      }, 0)
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 1) {
            return '合计消耗量（kg）'
          }
          if (columnIndex === 9) {
            return ` ${this.xhlCalAll().count1.toFixed(2)} `
          }
          if (columnIndex === 10) {
            return ` ${this.xhlCalAll().count2.toFixed(2)} `
          }
          return ''
        })
      ]
    },
    fhsjCountFpower(row) {
      return row.fpower
    },
    footerCellClassName({ $rowIndex, columnIndex }) {
      if (columnIndex === 7 || columnIndex === 8) {
        if ($rowIndex === 0) {
          return 'col-blue'
        }
      }
      if (columnIndex === 7 || columnIndex === 8) {
        if ($rowIndex === 1) {
          return 'col-red'
        }
      }
    },
    // 表尾数据
    fhsjMethod({ columns, data }) {
      setTimeout(() => {
        const $fhsjTable = this.$refs.fhsjTable
        if ($fhsjTable) {
          $fhsjTable.updateFooter()
        }
      }, 0)
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 1) {
            return '合计消耗量（kg）'
          }
          if (columnIndex === 9) {
            return ` ${this.xhlCalAll().count3.toFixed(2)} `
          }
          if (columnIndex === 10) {
            return ` ${this.xhlCalAll().count4.toFixed(2)} `
          }
          return ''
        }),
        columns.map((column, columnIndex) => {
          if (columnIndex === 1) {
            return '磨合燃油/气缸油总消耗量（kg）'
          }
          const {
            count1, count2,
            count3, count4 } = this.xhlCalAll()
          if (columnIndex === 9) {
            return ` ${(count1 + count3).toFixed(2)} `
          }
          if (columnIndex === 10) {
            return ` ${(count2 + count4).toFixed(2)} `
          }
          return ''
        })
      ]
    }

  }
}
</script>
<style scoped lang="scss">
  .input {
    width: 10%;
    margin-top: 10px;
    margin-bottom: 10px;
  }

  .drag-set-modal {
    width: 100%;
    margin-left: 60px;
  }

  .drag-input {
    float: left;
    position: relative;
    margin-bottom: -44px;
    z-index: 9999;
  }
  .drag-select {
    float: left;
    width: 12%;
    position: relative;
    margin-bottom: -60px;
    z-index: 9999;
    margin-left: 150px;
  }
  /deep/ .el-dialog__body {
    padding-top: 4px;
  }
  /deep/ .vxe-toolbar {
    margin-left: 360px;
  }

/deep/ .vxe-table--render-default .vxe-body--column.col--ellipsis, .vxe-table--render-default .vxe-footer--column.col--ellipsis, .vxe-table--render-default .vxe-header--column.col--ellipsis, .vxe-table--render-default.vxe-editable .vxe-body--column {
    height: 0px;
}

/deep/ .vxe-table--render-default .vxe-body--column {
  line-height: 16px;
}
/deep/ .vxe-table--render-default .vxe-body--column:not(.col--ellipsis) {
  height: 16px;
  line-height: 16px;
}
  .cb-set-modal ::v-deep .el-dialog__body {
    min-height: 350px!important;
    overflow: scroll;
  }
  .cb-set-modal ::v-deep .single-select-table thead .el-table-column--selection .cell {
    display: none;
  }
</style>
